<template>
  <view class="chat-container page-container">
    <!-- 医生信息卡片 -->
    <view class="doctor-card">
      <image :src="doctorInfo.avatar" class="doctor-avatar" mode="aspectFill" />
      <view class="doctor-info">
        <view class="name-title">
          <text class="doctor-name">{{ doctorInfo.name }}</text>
          <text class="doctor-title">{{ doctorInfo.title }}</text>
        </view>
        <view class="department">{{ doctorInfo.department }}</view>
        <view class="specialty">{{ doctorInfo.specialty }}</view>
      </view>
    </view>

    <!-- 聊天区域 -->
    <scroll-view 
      class="chat-content" 
      scroll-y 
      :scroll-into-view="scrollToMessage"
      :scroll-with-animation="true"
    >
      <view class="chat-list">
        <!-- 这里后续添加聊天消息列表 -->
      </view>
    </scroll-view>

    <!-- 输入区域 -->
    <view class="input-area">
      <input 
        type="text" 
        class="message-input"
        v-model="inputMessage"
        placeholder="请输入问题"
        @confirm="sendMessage"
      />
      <button class="send-btn" @tap="sendMessage">发送</button>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { onLoad } from '@dcloudio/uni-app';

interface DoctorInfo {
  id: number;
  name: string;
  department: string;
  title: string;
  avatar: string;
  specialty: string;
}

const doctorInfo = ref<DoctorInfo>({
  id: 0,
  name: '',
  department: '',
  title: '',
  avatar: '',
  specialty: ''
});

const inputMessage = ref('');
const scrollToMessage = ref('');

// 获取页面参数
onLoad((query) => {
  if (query?.doctor) {
    try {
      const doctor = JSON.parse(decodeURIComponent(query.doctor));
      doctorInfo.value = doctor;
      console.log('医生信息:', doctor);
    } catch (error) {
      console.error('解析医生信息失败:', error);
      uni.showToast({
        title: '获取医生信息失败',
        icon: 'none'
      });
    }
  }
});

// 发送消息
const sendMessage = () => {
  if (!inputMessage.value.trim()) {
    return;
  }
  // TODO: 实现发送消息逻辑
  console.log('发送消息:', inputMessage.value);
  inputMessage.value = '';
};
</script>

<style>
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #F5F8FF;
}

.doctor-card {
  display: flex;
  padding: 20rpx;
  background-color: #FFFFFF;
  margin: 20rpx;
  border-radius: 16rpx;
}

.doctor-avatar {
  width: 120rpx;
  height: 120rpx;
  border-radius: 60rpx;
  margin-right: 20rpx;
}

.doctor-info {
  flex: 1;
}

.name-title {
  display: flex;
  align-items: center;
  margin-bottom: 8rpx;
}

.doctor-name {
  font-size: 32rpx;
  font-weight: bold;
  color: #333333;
  margin-right: 16rpx;
}

.doctor-title {
  font-size: 24rpx;
  color: #666666;
  background-color: #F5F8FF;
  padding: 4rpx 12rpx;
  border-radius: 8rpx;
}

.department {
  font-size: 28rpx;
  color: #666666;
  margin-bottom: 8rpx;
}

.specialty {
  font-size: 26rpx;
  color: #999999;
}

.chat-content {
  flex: 1;
  padding: 20rpx;
}

.input-area {
  display: flex;
  padding: 20rpx;
  background-color: #FFFFFF;
  border-top: 1rpx solid #EEEEEE;
}

.message-input {
  flex: 1;
  height: 80rpx;
  background-color: #F5F8FF;
  border-radius: 40rpx;
  padding: 0 30rpx;
  margin-right: 20rpx;
  font-size: 28rpx;
}

.send-btn {
  width: 120rpx;
  height: 80rpx;
  background-color: #4A90E2;
  color: #FFFFFF;
  border-radius: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28rpx;
  padding: 0;
  margin: 0;
}

.send-btn:active {
  background-color: #3A80D2;
}
</style> 